﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmUpdateTime : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private int int_1 = 0;
        protected Label labLessionName;
        protected Label labStudyTime;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        private string string_0 = "A";
        protected Button update;
        protected UpdatePanel UPPart;

        private void method_0(int int_2)
        {
            string str2;
            double num = 0.0;
            double num2 = 0.0;
            string str = "";
            str2 = str2 = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            SqlConnection connection = new SqlConnection(str2);
            connection.Open();
            SqlCommand command = new SqlCommand("select PlanName,StudyLongTime,StudyFen from StudyPlanInfo where ID=" + this.int_0, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                num = Convert.ToDouble(reader["StudyLongTime"].ToString()) * 60.0;
                num2 = Convert.ToDouble(reader["StudyFen"].ToString());
                str = reader["PlanName"].ToString();
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            if ((Convert.ToDouble(int_2) >= num) && (this.publicFun_0.GetValues(string.Concat(new object[] { "select ID from UserStudyFen where ExamOrStudy='S' and UserCode='", this.httpCookie_0.Value, "' and FormID=", this.int_0 }), "ID") == ""))
            {
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('", this.httpCookie_0.Value, "','", str, "','", num2, "','StudyPlanInfo','", this.int_0, "','S')" }));
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["PlanID"].ToString());
                this.int_1 = Convert.ToInt32(base.Request["DocID"].ToString());
                this.string_0 = base.Request["TypeID"].ToString();
                if (!base.IsPostBack)
                {
                    if (this.string_0 == "B")
                    {
                        this.labLessionName.Text = this.publicFun_0.GetValues("select LessionName from LessionInfo where ID=" + this.int_1, "LessionName");
                    }
                    else
                    {
                        this.labLessionName.Text = this.publicFun_0.GetValues("select SubjectName from BookInfo where ID=" + this.int_1, "SubjectName");
                    }
                    int num = 0;
                    string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select CountTime from StudyUser where UserCode='", this.httpCookie_0.Value, "' and PlanID=", this.int_0 }), "CountTime");
                    if (values.Trim() == "")
                    {
                        values = "0";
                    }
                    num = Convert.ToInt32(values);
                    if (num != 0)
                    {
                        this.labStudyTime.Text = Convert.ToInt32((int) (num / 60)) + "小时";
                        this.labStudyTime.Text = this.labStudyTime.Text + Convert.ToInt32((int) (num % 60)) + "分";
                    }
                    else
                    {
                        this.labStudyTime.Text = "0小时0分";
                    }
                    this.publicFun_0.ExecuteSql(string.Concat(new object[] { "Delete from Systip where GetNumber='", this.httpCookie_0.Value, "' and Formtable='StudyPlanInfo' and FormID=", this.int_0 }));
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }

        protected void update_Click(object sender, EventArgs e)
        {
            string str = Convert.ToString(base.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
            switch (str)
            {
                case "":
                case null:
                    str = Convert.ToString(base.Request.ServerVariables["REMOTE_ADDR"]);
                    break;
            }
            string values = this.publicFun_0.GetValues("select top 1 LastDate from StudyUser where UserCode='" + this.httpCookie_0.Value + "' order by LastDate desc", "LastDate");
            string str3 = base.Request.Form["passedtime"].Trim();
            if (values.Trim() != "")
            {
                if (DateTime.Now.AddMinutes(-10.0) < Convert.ToDateTime(values))
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckTip", "alert('请认真学习,不要作弊！')", true);
                    return;
                }
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "update StudyUser set CountTime=CountTime+", str3, ",LoginIP='", str, "',LastDate=getdate() where UserCode='", this.httpCookie_0.Value, "' and PlanID=", this.int_0 }));
            }
            else
            {
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "update StudyUser set CountTime=CountTime+", str3, ",LoginIP='", str, "',LastDate=getdate() where UserCode='", this.httpCookie_0.Value, "' and PlanID=", this.int_0 }));
            }
            int num = 0;
            string str2 = this.publicFun_0.GetValues(string.Concat(new object[] { "select CountTime from StudyUser where UserCode='", this.httpCookie_0.Value, "' and PlanID=", this.int_0 }), "CountTime");
            if (str2.Trim() == "")
            {
                str2 = "0";
            }
            num = Convert.ToInt32(str2);
            if (num != 0)
            {
                this.labStudyTime.Text = Convert.ToInt32((int) (num / 60)) + "小时";
                this.labStudyTime.Text = this.labStudyTime.Text + Convert.ToInt32((int) (num % 60)) + "分";
            }
            else
            {
                this.labStudyTime.Text = "0小时0分";
            }
            this.method_0(num);
            base.Response.Redirect(base.Request.Url.AbsoluteUri);
        }
    }
}

